package Bean;

import org.apache.hadoop.io.Writable;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

public class JobPerCityBean implements Writable, Comparable<JobPerCityBean> {
    private String city;
    private String jobType;
    private int count;

    public JobPerCityBean() {}

    public JobPerCityBean(String city, String jobType) {
        this.city = city;
        this.jobType = jobType;
        this.count = 1;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(city);
        out.writeUTF(jobType);
        out.writeInt(count);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        city = in.readUTF();
        jobType = in.readUTF();
        count = in.readInt();
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getJobType() {
        return jobType;
    }

    public void setJobType(String jobType) {
        this.jobType = jobType;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public String getCityJobType() {
        return city + "_" + jobType;
    }

    @Override
    public String toString() {
        return String.format("%s %s\t%d", city, jobType, count);
    }

    @Override
    public int compareTo(JobPerCityBean o) {
        return Integer.compare(o.count, this.count);
    }

    public static void sort(List<JobPerCityBean> list) {
        Collections.sort(list);
    }
}